<template>
  <el-drawer
    :visible.sync="drawer"
    direction="rtl"
    size="50%"
    :with-header="false"
    :width="700"
  >
    <div class="drawer_box">
      <div class="drawer_title">
        <div class="drawer_t">
          <div class="drawer_t_l">
            <img
              class="drawer_t_l_img"
              src="/static/skin/herodoo/main/platform/home/img/piliangoumai.png"
              alt=""
            />
            新增主题类型
          </div>
          <img
            class="drawer_t_r"
            src="/static/skin/herodoo/main/platform/home/img/guanbi.png"
            alt=""
            @click="drawer = false"
          />
        </div>
      </div>
      <div class="drawer_content">
        <div class="list-box">
          <div class="left">排序:</div>
          <div class="right">
            <el-input-number
              v-model="form.sort"
              @change="handleChange"
              :min="1"
              label="排序"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input-number>
          </div>
        </div>
        <div class="list-box">
          <div class="left">主题类型中文简体名称：</div>
          <div class="right">
            <el-input
              v-model="form.zn"
              placeholder="主题类型中文简体名称"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input>
          </div>
        </div>
        <div class="list-box">
          <div class="left">主题类型中文繁体名称：</div>
          <div class="right">
            <el-input
              v-model="form.cn"
              placeholder="主题类型中文繁体名称"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input>
          </div>
        </div>
        <div class="list-box">
          <div class="left">主题类型文英文名称：</div>
          <div class="right">
            <el-input
              v-model="form.en"
              placeholder="主题类型中文英文名称"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input>
          </div>
        </div>
        <div class="list-box">
          <div class="left">主题类型日文名称：</div>
          <div class="right">
            <el-input
              v-model="form.jn"
              placeholder="主题类型中文日文名称"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input>
          </div>
        </div>
        <div class="list-box">
          <div class="left">主题类型韩文名称：</div>
          <div class="right">
            <el-input
              v-model="form.kn"
              placeholder="主题类型中文韩文名称"
              :disabled="isEdit == 'look' ? true : false"
            ></el-input>
          </div>
        </div>
        <div class="list-box" v-if="type == 'look'">
          <div class="left">操作人：</div>
          <div class="right">
            admin
          </div>
        </div>
        <div class="list-box" v-if="type == 'look'">
          <div class="left">操作时间：</div>
          <div class="right">
            2024-6-30
          </div>
        </div>
      </div>

      <div class="button_list" v-if="isEdit != 'look'">
        <button @click="save()">保存</button>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  name: "cat_dialog",
  props: {
    // isEdit: {
    //   type: Boolean,
    //   default: true
    // }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      isEdit: "look",
      form: {
        sort: 1, //排序
        zn: "", //中文
        cn: "", //繁体
        en: "", // 英文
        jn: "", //日文
        kn: "", //韩文
        ID: ""
      },
      rules: {
        zn: { required: true, message: "请输入主题类型中文简体名称" }
        // cn: { required: true, message: "请输入主题类型中文繁体名称" },
        // en: { required: true, message: "请输入主题类型中文英文名称" },
        // jn: { required: true, message: "请输入主题类型中文日文名称" },
        // kn: { required: true, message: "请输入主题类型中文韩文名称" },
      }
    };
  },
  created() {},
  watch: {},
  methods: {
    drawerOpen(data = null, type = "CREATE") {
      // editType 是否可编辑，打他 父级传的数据，type  是新建还是更新
      this.drawer = true;
      this.isEdit = type;
      if (!data) {
        this.form.zn = "";
        this.form.sort = 1;
        this.form.cn = "";
        this.form.en = "";
        this.form.jn = "";
        this.form.kn = "";
        this.form.ID = "";
        return;
      } else {
        this.form.zn = data.Name;
        this.form.sort = data.Sort;
        this.form.ID = data.ID;
        this.form.cn = data.Name_ZH
        this.form.en = data.Name_EN
        this.form.jn = data.Name_JP
        this.form.kn = data.Name_KP
      }
    },
    save() {
      if (!this.octopus.tools.verify(this.form, this.rules)) {
        return;
      }
      this.$confirm(`确定保存这个主题类型吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        // type: 'warning'
        center: true
      })
        .then(res => {
          this.update_api_1276();
        })
        .catch(() => {
          console.log("取消了");
        });
    },
    update_api_1276() {
      let cellDate = [
        { name: "Name", defaultValue: this.form.zn }, // 主题/热点名称
        { name: "Sort", defaultValue: this.form.sort }, // 排序优先级
        { name: "TypeID", defaultValue: 1 } // 类型ID 1为主题 ，2为热门
      ];
      if (this.isEdit == "CREATE") {
        cellDate.push({
          name: "CreateTime",
          defaultValue:
            new Date().toJSON().substring(0, 10) +
            " " +
            new Date().toTimeString().substring(0, 8)
        });
        cellDate.push({
          name: "CreateUserID",
          defaultValue: this.octopus.passport.id
        });
      } else {
        cellDate.push({
          name: "UpdateTime",
          defaultValue:
            new Date().toJSON().substring(0, 10) +
            " " +
            new Date().toTimeString().substring(0, 8)
        });
        cellDate.push({
          name: "UpdateUserID",
          defaultValue: this.octopus.passport.id
        });
      }
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1276,
          type: this.isEdit,
          value: this.isEdit == "CREATE" ? "" : this.form.ID,
          cellData: cellDate,
          paramData: {}
        },
        data => {
          if (data.status.code == 200) {
            this.drawer = false;
            this.octopus.tips.success("操作成功。");
            this.$emit("reload");
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    }
  }
};
</script>
<style scoped>
.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_title {
  box-shadow: 0px 5px 5px rgb(230 228 228 / 30%);
  padding-bottom: 1rem;
  font-size: 1.6rem;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 2rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.button_box {
  margin-top: 1rem;
  padding: 0 3rem;
  display: flex;
}

.drawer_content {
  overflow-y: auto;
  margin-top: 1.5rem;
  height: calc(100vh - 11rem);
  padding: 0 3rem;
  width: 100%;
  padding-bottom: 1rem;
}

.drawer_content .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_content .driver-title {
  margin-top: 1em;
}

.content-box {
  display: flex;
  align-items: center;
  margin: 2rem 0 2rem 2em;
}

.mt-10 {
  margin-top: 10rem;
}

.content-box .label {
  width: 25%;
  font-size: 1.6rem;
}

.content-box .label .label-bold {
  font-size: 1.8rem;
  font-weight: bold;
}

.content-box .desc {
  flex: 1;
  font-size: 1.6rem;
}

.list-box {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

.list-box {
  line-height: 4rem;
  margin-top: 2rem;
}

.list-box .left {
  width: 20%;
  font-size: 1.5rem;
}

.list-box .right {
  width: 80%;
}

.button_list {
  margin-top: 1rem;
  display: flex;
  justify-content: end;
  position: absolute;
  background-color: #ffff;
  bottom: 1rem;
  width: calc(100% - 7rem);
}

.button_list button {
  border: none;
  height: 4rem;
  width: 12rem;
  border-radius: 1rem;
  margin-left: 1rem;
  color: #ffff;
  background-color: #f78c53;
  cursor: pointer;
}
</style>
